/*
 *  Copyright (C) 2010 Zubanov Dmitry
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


/**
 *
 * @author Zubanov Dmitry aka javadimon, zubanov@gmail.com
 * Omsk, Russia, created 25.09.2010
 * (C) Copyright by Zubanov Dmitry
 */

package org.jssdb.core.net;

import java.io.Serializable;
import java.text.MessageFormat;
import org.jssdb.core.query.Request;

public class CarrierRequestResponse implements Serializable{
    
    private long id;
    private String oqlRequest, remoteHost, myHost;
    private Request request;
    public static int ADD = 0, MODIFY = 1, DELETE = 2, ADDED_OK = 3,
            MODIFIED_OK = 4, DELETED_OK = 5, ADDED_FALSE = 6,
            MODIFIED_FALSE = 7, DELETED_FALSE = 8;
    private int action = -1, status = -1, remotePort, myPort;
    private long transferObjectId = -1;
    private Object resultObject, transferObject;
    private static final long serialVersionUID = 3446901256057227801L;

    /**
     * 
     * @param id
     * @param remoteHost
     * @param remotePort
     * @param myHost
     * @param myPort
     */
    public CarrierRequestResponse(long id, String remoteHost,
            int remotePort, String myHost, int myPort){
        this.id = id;
        this.remoteHost = remoteHost;
        this.remotePort = remotePort;
        this.myHost = myHost;
        this.myPort = myPort;
    }

    public void setRequest(Request request){
        this.request = request;
    }

    public Request getRequest(){
        return request;
    }

    public long getTransferObjectId(){
        return transferObjectId;
    }

    public void setTransferObjectId(long id){
        transferObjectId = id;
    }

    public void setStatus(int status){
        this.status = status;
    }

    public int getStatus(){
        return status;
    }

    public void setOQLRequest(String request){
        this.oqlRequest = request;
    }

    public void setAction(int action){
        this.action = action;
    }

    public void setResultObject(Object obj){
        resultObject = obj;
    }

    public void setTransferObject(Object obj){
        transferObject = obj;
    }

    public int getAction() {
        return action;
    }

    public long getId() {
        return id;
    }

    public String getMyHost() {
        return myHost;
    }

    public int getMyPort() {
        return myPort;
    }

    public String getRemoteHost() {
        return remoteHost;
    }

    public int getRemotePort() {
        return remotePort;
    }

    public String getOQLRequest() {
        return oqlRequest;
    }

    public Object getResultObject() {
        return resultObject;
    }

    public Object getTransferObject() {
        return transferObject;
    }

    @Override
    public String toString(){
        String resultObjectClass = "null";
        if(resultObject != null){
            resultObjectClass = resultObject.getClass().getName();
        }

        String transferObjectClass = "null";
        if(transferObject != null){
            transferObjectClass = transferObject.getClass().getName();
        }

        return MessageFormat.format("Id {0}, my host {1}, my port {2}, "
                + "remote host {3}, remote port {4}, request {5}, action {6},"
                + "result object class {7}, transfer object {8}",
                new Object[]{id, myHost, myPort, remoteHost, remotePort,
                oqlRequest, action, resultObjectClass, transferObjectClass});
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CarrierRequestResponse other = (CarrierRequestResponse) obj;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 37 * hash + (int) (this.id ^ (this.id >>> 32));
        return hash;
    }

    

}
